import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home.vue'),
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('@/views/About.vue'),
  },
  {
    path: '/404',
    name:'404',
    component:() => import('@/views/error/404.vue'),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});
router.beforeEach((to: any, form: object, next: Function) => { 
  document.title = to.name;
  if(to.matched.length === 0){
   next('/404')
  }else{
    next()
  }
  
})
export default router;
